<?php
include_once("conn.php");//链接数据库文件引用
if(!($_POST['name']and$_POST['class']and$_POST['kaochang']and$_POST['time']and$_POST['teacher'])){//判断输入的数据是否为空
	echo "输入不允许为空。单击<a href='javascript:onclick=history.go(-1)'>这里</a>返回";
}
elseif(isset($_POST['tianjia']))
{
	// $sql1="select * from anpai";
	// $rs=$pdo->query($sql1);
	// $all=$rs->fetchAll(PDO::FETCH_ASSOC);
	// $num=count($all+1)
	
	$sql="insert into anpai values('{$_POST['id']}','{$_POST['class']}','{$_POST['name']}','{$_POST['kaochang']}','{$_POST['time']}','{$_POST['teacher']}')";
	// $sql="insert into anpai values(1,'软工2班','php','化工316','哈哈哈','asdhisad')";
	
	$result=$pdo->exec($sql);
	if($result)//判断插入是否成功
	{
		echo "添加成功，单击<a href='se.php'>这里</a>查看";
	}
	else
	{
		echo "{$_POST['id']}";
	}
}elseif (isset($_POST['xiugai'])) {
	
	$sql="update anpai set teacher='{$_POST['teacher']}',time='{$_POST['time']}',class='{$_POST['class']}',name='{$_POST['name']}',kaochang='{$_POST['kaochang']}' where id='{$_POST['id']}'";//定义修改语句
	$result=$pdo->exec($sql);
	if($result)//判断插入是否成功
	{
		echo "修改成功，单击<a href='se.php'>这里</a>查看";
	}
	else
	{
		echo "<script>alert('修改失败或者您未做任何修改');history.go(-1);</script>";
	}
}
?>